﻿using System;
using System.Linq;

using Fuse8.DomainFramework.Common.Locator;
using Fuse8.DomainFramework.DataAccess;
using Fuse8.DomainFramework.DataAccess.SqlDatabase;

using Fuse8.ContentManagementFramework.Domain.Commands;
using Fuse8.ContentManagementFramework.Domain;

namespace Fuse8.ContentManagementFramework.DataAccess.SqlAccess.Commands
{
    internal class CmsEntityAnnotationSaveForEntityDataCommand : CmsEntityAnnotationSaveForEntityCommand
    {
        public override IQueryable<CmsEntityAnnotation> Execute()
        {
            var factory = DependencyServiceLocator.Current.GetInstance<IUnitOfWorkFactory<CmsEntityAnnotation>>();

            var currentUnitOfWork = factory.Get(false) as SqlUnitOfWork<CmsEntityAnnotation>;

            if (currentUnitOfWork != null)
            {
                var mapper = DependencyServiceLocator.Current.GetInstance<ISqlEntityDataMapper<CmsEntityAnnotation, int>>();

                SqlUtility<CmsEntityAnnotation, int>.ExecuteNonQuery(
                    currentUnitOfWork.Connection,
                    currentUnitOfWork.Transaction,
                    "cms_sp_EntityAnnotationSaveMany",
                    CommandParameter,
                    mapper);
            }

            return null;
        }
    }
}
